<template>
  <div class="login">
    <div class="login-box">
      <span class="login-box__title">后台管理系统</span>
      <div class="login-box__input">
        <el-input
          placeholder="请输入账号"
          prefix-icon="el-icon-user-solid"
          v-model="loginForm.account"
        >
        </el-input>
        <el-input
          show-password
          placeholder="请输入密码"
          prefix-icon="el-icon-lock"
          v-model="loginForm.password"
          style="margin: 20px 0"
        >
        </el-input>
      </div>
      <el-button @click="login">登陆</el-button>
    </div>
  </div>
</template>

<script>
import loginApi from "@/api/login";
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {
      loginForm: {
        account: "",
        password: "",
      },
    };
  },
  computed: {
    ...mapGetters(["isLogin"]),
  },
  created() {
    console.log("login created");
  },
  methods: {
    ...mapActions(["setLogin"]),
    // 登录
    async login() {
      const res = await loginApi.login(this.loginForm);
      console.log(res.code === 200);
      if (res.code === 200) {
        this.setLogin(true);
        this.$router.push("/");
      } else if (res.code === 401) {
        this.$message.error(res.msg);
      }
    },
  },
};
</script>

<style scoped lang="less">
.login {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: url("~@/assets/image/background.jpg") no-repeat center center;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
  &-box {
    width: 30%;
    height: 40%;
    text-align: center;
    border-radius: 5px;
    background-color: #ffffff;
    opacity: 0.9;
    &__title {
      color: #498cc5;
      line-height: 3;
      font-size: 30px;
    }
    &__input {
      margin: 10px auto;
      width: 350px;
    }
  }
}

/deep/ .el-button {
  width: 350px;
  color: white;
  background-color: #4e8fc6;
}
</style>